package com.ruoyi.newRepair.mapper;

import com.ruoyi.newRepair.domain.*;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Date;
import java.util.List;
import java.util.Map;


@Mapper
public interface RepairOrderMapper {

    //    设备编号详情
    List<RepairOrder> getEquipmentNoDetails(@Param("equipmentNo") String equipmentNo,
                                            @Param("startDate") String startDate,
                                            @Param("endDate") String endDate,
                                            @Param("completedByName") String completedByName);

    //设备完成时长图
    List<EquipmentStatsDTO> getTop10EquipmentStats();

    //帕累托图
    List<FaultCategoryStats> selectFaultCategoryStats();

    //控制图
    @Select("SELECT completion_duration AS completionDuration FROM jr_repair_order")
    List<RepairOrder> selectAllDurations();

    List<Double> selectCompletionDurations();

    //设备类型统计故障
    List<FailureStatisticVO> selectFailureStatistics(@Param("startDate") String startDate,
                                                     @Param("endDate") String endDate);

    //聚类分析
    @Select("SELECT failure_phenomenon as failurePhenomenon, failure_cause as failureCause FROM jr_repair_order")
    List<RepairOrder> selectFailureData();

    @MapKey("equipmentTypeName")
    List<Map<String, Object>> selectFailureDetails(String deviceType, String formattedStart, String formattedEnd);


    @Select("SELECT completion_duration as completionDuration FROM jr_repair_order")
    List<RepairOrder> selectRepairNumberData();

    //    设备编号统计
    List<EquipmentNo> selectEquipmentData(@Param("equipmentNo") String equipmentNo,
                                          @Param("startDate") String startDate,
                                          @Param("endDate") String endDate);

    Long getEquipmentNoDetailsActions(@Param("equipmentNo") String equipmentNo,
                                      @Param("startDate") String startDate,
                                      @Param("endDate") String endDate,
                                      @Param("completedByName") String completedByName);

    //    MTTR
    List<RepairOrder> selectAllForMTTR(@Param("startDate") String startDate, @Param("endDate") String endDate, @Param("equipmentId") String equipmentId);

    //    MTBF
    List<RepairOrder> selectAllForMTBF(@Param("startDate") String startDate, @Param("endDate") String endDate, @Param("equipmentId") String equipmentId);

    //    总利用率统计
    List<RepairOrder> selectAllForUR(@Param("startDate") String startDate, @Param("endDate") String endDate, @Param("equipmentId") String equipmentId);

    // 查询最新的 completion_time
    @Select("SELECT MAX(completion_time) FROM jr_repair_order WHERE completion_time IS NOT NULL")
    Date selectLatestCompletionTime();

    // 查询最早的 receive_time
    @Select("SELECT MIN(receive_time) FROM jr_repair_order WHERE receive_time IS NOT NULL")
    Date selectEarliestReceiveTime();

    //    设备类型查询
    List<EquipmentType> getEquipmentId();

    //    设备台数
    List<EquipmentCountDTO> countEquipment();

    //    总维修时长统计
    List<CountRepair> countfix(@Param("startDate") String startDate, @Param("endDate") String endDate, @Param("equipmentId") String equipmentId);

    //    总故障周趋势
    List<TotalFailure> totalFailure();

    //    上周设备故障分布图
    List<LastWeekFailure> getLastWeekFailureDetails();

    //    具体设备维修单分布
    List<SpecificEquipment> getSpecificEquipment(String deviceType);

    //    OEE设备选取
    List<EquipmentType> getOEEEquipmentId();

    //    OEE Q1/2
    List<OEE> countOEEQ1(@Param("machineNo") String machineNo,@Param("startDate") String startDate,@Param("endDate") String endDate);

    //    OEE Q3
    List<Production> countOEEQ3(@Param("processSiteNo") String processSiteNo, @Param("minYearWeek") String minYearWeek, @Param("maxYearWeek") String maxYearWeek);

}

